<?php

namespace app\common\job;

use app\common\model\Consulting;
use app\index\service\ConsultingLawyerMatchV2Service;
use think\facade\Log;
use think\queue\Job;

/**
 * 律师匹配
 * Class ConsultingLawyerMatchV2
 * @version V2.0
 * @package app\common\job
 */
class ConsultingLawyerMatchV2
{
    /**
     * fire是消息队列默认调用的方法
     * @param Job $job 当前的任务对象
     * @param array|mixed $data 发布任务时自定义的数据
     */
    public function fire(Job $job, $data)
    {
        $id = $data['id'] ?? null;
        $messageId = $data['messageId'] ?? null;
        $businessType = $data['businessType'] ?? null;

        try {

            // 下一步
            if($businessType == Consulting::BT_RANDOM){
                $this->getConsultingLawyerMatchV2Service()->matchRandomStep2($id, $messageId);
            }elseif ($businessType == Consulting::BT_DESIGNATED){
                $this->getConsultingLawyerMatchV2Service()->matchDesignateStep2($id, $messageId);
            }

        } catch (\Exception $exception) {
            Log::error('消费队列：' . $exception->getMessage());
        } finally {

            $job->delete();
        }

    }

    private function getConsultingLawyerMatchV2Service(): ConsultingLawyerMatchV2Service
    {
        return app(ConsultingLawyerMatchV2Service::class);
    }

}
